/*this module is coded by user according to their requirements */

#include "zdfl_parameter_define.h"
#include "app_OSD.h"
#include "User_handle.h"
#include "app_MSG.h"
#include "Printf.h"
#include "app_SRC.h"
#include "app_GUI.h"
#include "app_MSG.h"
#include "AdjTSC.h"
#include "dv_OSD.h"

extern int  OSDLang; //this variable is used for setting muti-language
extern U8 CurHidePageID;

extern U16 StartPtX;
extern U16 StartPtY;
U8 MoveStatus=0xff;
U16 X_Old,Y_Old;
S16 SlideValue;
S16 current_position = 0;

#ifdef USED_USER_BTN_CODE
/***********************************************************
this part is used for dealing with callback function binded with button;

If USED_USER_BTN_CODE is defined, you must copy these callback functions from Zdfl_app_ctrl.c  
to here, then according to yourselves requriments to realize all kinds of target;

void InitCtrlValue(HUICTRL hCtrl);
You can initial the all kinds of ctrl values, including the eeprom value;

void InitPageValue(HUICTRL page_id);
you can initial the pager values, 
************************************************************/

void _OSDCommon_Update_ProgressBar_Status( U16 Ctrl, U8 Value );
void _OSDCommon_Update_ProgressBar_Value( U16 Ctrl, U8 Value );
/********************OSDSetupPager************************/
U8 LanguageStatus=0;
U8 TimeOutStatus=0;
U8 TransparentValue=0;
void _OSDSetupPager_Update_Language_Status( U16 Ctrl, U8 Value );
U8 GetLanguageStatus(void);
void SetLanguageStatus(U8 value);
void _OSDSetupPager_Update_TimeOut_Status( U16 Ctrl, U8 Value );
U8 GetTimeOutStatus(void);
void SetTimeOutStatus(U8 value);
U8 GetTransparentValue(void);
void SetTransparentValue(U8 value);

/********************VideoSetupPager************************/
U8 BrightnessValue=30;
U8 ContrastValue=30;
U8 SaturationValue=30;
U8 GetBrightnessValue(void);
void SetBrightnessValue(U8 value);
U8 GetContrastValue(void);
void SetContrastValue(U8 value);
U8 GetSaturationValue(void);
void SetSaturationValue(U8 value);

/********************RadioPager************************/
U16 RadioShowStringStatus=87;
U8 RadioShowProValue=30;
void _OSDRadioPager_Update_FreString_Status( U16 Ctrl, U16 Value );
U16 GetFreStringStatus(void);
void SetFreStringStatus(U16 value);
U8 GetFreProValue(void);
void SetFreProValue(U8 value);

/********************BlueToothPager************************/
U16 DialP[]={0,0};
U16 DialNum[]={0,0,0,0,0,0,0,0,0,0,0,0};
U8 DialStringStatus=0;
void _OSDBlueToothPager_Update_DialString_Status( U16 Ctrl, U8 Value );
U8 GetDialStringStatus(void);
void SetDialStringStatus(U8 value);

/********************PIPSettingPager************************/
APP_SRC PIPSourceStatus=CVBS;
APP_PIP_SIZE PIPSizeStatus=SMALL;
APP_PIP_POS PIPPositionStatus=LEFT_TOP;
U8 PIPTransValue=30;
void _OSDPIPSettingPager_Update_PIPSource_Status( U16 Ctrl, APP_SRC Value );
U8 GetPIPSourceStatus(void);
void SetPIPSourceStatus(APP_SRC value);
void _OSDPIPSettingPager_Update_PIPSize_Status( U16 Ctrl, APP_PIP_SIZE Value );
U8 GetPIPSizeStatus(void);
void SetPIPSizeStatus(APP_PIP_SIZE value);
void _OSDPIPSettingPager_Update_PIPPosition_Status( U16 Ctrl, APP_PIP_POS Value );
U8 GetPIPPositionStatus(void);
void SetPIPPositionStatus(APP_PIP_POS value);
U8 GetPIPTransparentValue(void);
void SetPIPTransparentValue(U8 value);

/*******************SourceSelectPager***********************/
APP_SRC MainSourceStatus=CVBS;


/*******************OSGDemoPager****************************/
extern void GridLineDemo( void );
extern void SpeedoMeterDemo( void );
extern void RoseDemo( void );
extern void SlideDemo( void );

#ifdef Update_AvoidBlink //erek 2011-1-27 for bank overflow issue
U8 UpdateStatus=0;
#endif


#ifdef Update_AvoidBlink //erek 2011-1-27 for bank overflow issue
void TWLL_UpdateButton_WithBT(U16 Ctrl);
void TWLL_UpdateProgressBar_WithBT(U16 Ctrl);
#endif


#ifdef Update_AvoidBlink //erek 2011-1-27 for bank overflow issue
void TWLL_UpdateButton_WithBT(U16 Ctrl)
{
	LPUIPBUTTON lpBtn;
	U8 CanvasID;
	U16 X, Y, Width, Height, BMPID;

	lpBtn    = (LPUIPBUTTON)GetCtrlHandle(Ctrl);
	CanvasID = TWLL_Get_ImageCanvas(lpBtn->hImageID[ZCTRL_UNFOCUS], IconShowOnCanvas);
	TWLL_Get_IconShowOnCanvasXY(lpBtn->hImageID[ZCTRL_UNFOCUS], IconShowOnCanvas, &X, &Y);
	BMPID = TWLL_Get_ImageID(lpBtn->hImageID[ZCTRL_UNFOCUS], IconShowOnCanvas);
	TWLL_Get_ImageSize(BMPID, &Width, &Height);

	UpdateStatus = 1;
	ZUIRedrawCtrl(Ctrl);
	
	TWLL_WaitOSDBlank(1);
	TWLL_BlockTransfer((User_Canvas[CanvasID].Mem_X+X+800), (User_Canvas[CanvasID].Mem_Y+Y), Width, Height, (User_Canvas[CanvasID].Mem_X+X), (User_Canvas[CanvasID].Mem_Y+Y), User_Canvas[CanvasID].Bits_Per_Pixel);
	UpdateStatus = 0;
}

void TWLL_UpdateProgressBar_WithBT(U16 Ctrl)
{
	LPUIPROGRESS  lpPro;
	U8 CanvasID;
	U16 X,Y,Width,Height,BMPID;

	lpPro=(LPUIPROGRESS )GetCtrlHandle(Ctrl);
	CanvasID=TWLL_Get_ImageCanvas(lpPro->hImage[ZPRO_IMAGE_BACKGROUND],IconShowOnCanvas);
	TWLL_Get_IconShowOnCanvasXY(lpPro->hImage[ZPRO_IMAGE_BACKGROUND],IconShowOnCanvas,&X,&Y);
	BMPID=TWLL_Get_ImageID(lpPro->hImage[ZPRO_IMAGE_BACKGROUND],IconShowOnCanvas);
	TWLL_Get_ImageSize(BMPID,&Width,&Height);

	UpdateStatus=1;
	ZUIRedrawCtrl(Ctrl);
	
	TWLL_WaitOSDBlank(1);
	TWLL_BlockTransfer((User_Canvas[CanvasID].Mem_X+X+800),(User_Canvas[CanvasID].Mem_Y+Y),Width,Height,(User_Canvas[CanvasID].Mem_X+X),(User_Canvas[CanvasID].Mem_Y+Y),User_Canvas[CanvasID].Bits_Per_Pixel);
	UpdateStatus=0;
}
#endif

extern void * CONST app_ui_ctrls[];

void change_button(LPUIPAGE page, U8 dir, int value)
{	
    static int ii, jj, aindex=-1, rindex=0;
    static U16 aretIndex,Active_Control_ID,Start_CID,End_CID,PWinCtrlID;
    static LPUIPAGE lpPage;
    static U8 PagerID,NWINNO,NPalette_ID,cnt=0;
	LPBASICWIN pwin;

    PagerID           = HOMEPAGE_IDX;   //because the indirect callback funciton will destroy the space of local variable,
    NWINNO            = page->nWinno;//because the indirect callback funciton will destroy the space of funciton parameters,
    Active_Control_ID = page->active_ctrl_id;
    NPalette_ID       = page->nPalette_id;
    Start_CID         = page->start_cid;
    End_CID           = page->end_cid;

    for (jj = Start_CID; jj < End_CID; jj ++)
    {
        pwin = app_ui_ctrls[jj];
		PWinCtrlID = pwin->CtrlID;
        if (pwin)
        {
            if ((U16)(pwin->hParent) == (U16)PagerID)
            {
                if (pwin->type[0] == WGUI_BUTTON)
            	{
	            	LPUIPBUTTON button = (LPUIPBUTTON)pwin;

					if (dir == APP_TSC_L)
					{
						button->rect.left -= value;
						if ((U16)65535 != button->hImageID[ZCTRL_UNFOCUS])
						{
							IconShowOnCanvas[button->hImageID[ZCTRL_UNFOCUS]].DispControl->XY1.X -= value;
						}
					}
					else if (dir == APP_TSC_R)
					{
						button->rect.left += value;
						if ((U16)65535 != button->hImageID[ZCTRL_UNFOCUS])
						{
							IconShowOnCanvas[button->hImageID[ZCTRL_UNFOCUS]].DispControl->XY1.X += value;
						}
					}            	
            	}
            }
        }
    }	
}

// Pager reply function for touch moving and move end message:
/*
 Function name: OnHomePageTouchMoving
 Page name:     HomePage
 Page id:       0
 */
void OnHomePageTouchMoving(U16 px, U16 py)
{
	#ifdef Support_PagerSlide
	static U8	moveDir,CanNum;
	static U16  X_New,Y_New;
	LPUIPAGE  lpPage;
	int value = 0;

	//py highest three bits indicate move direction, 000 is up, 010 is down, 100 is left, 110 is right
	moveDir=py>>13;
	X_New=px;
	Y_New=py&0x1fff;

	//Printf("\r\n OnHomePageTouchMoving");

	//Printf("\nmoveDir=%bx,X_New=%d,Y_New=%x\r\n",moveDir,X_New,Y_New);

	if (MoveStatus == 0xff)
	{
		lpPage=(LPUIPAGE)GetPageHandle(HOMEPAGE_IDX);
		CanNum = lpPage->nWinno;
		if (moveDir == APP_TSC_L)// direction is left
		{
			Printf("\nstart to move left %d\n", current_position);

			MoveStatus = moveDir;
			SlideValue = 0;
			X_Old = StartPtX;
			SlideValue += (X_Old - X_New);
			X_Old = X_New;
//			current_position += SlideValue;
			if ((current_position + SlideValue) <= (1271 - 480))
			{
				current_position += SlideValue;
//				User_Canvas[CanNum].Mem_X = current_position;
				TWLL_WaitDisplayBlank(1);
//				TWLL_Canvas_Init(&User_Canvas[CanNum]);
//				TWLL_BlockTransfer(0, 480+272, 480, 50, current_position, 480, 16); //re-draw setup bar
				TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
			}
		}
		else if (moveDir == APP_TSC_R)// direction is right
		{
			Printf("\nstart to move right %d\n", current_position);
			MoveStatus = moveDir;
			SlideValue = 0;
			X_Old = StartPtX;
			SlideValue = (X_New-X_Old);
			X_Old = X_New;
//			current_position -= SlideValue;
			if ((current_position - SlideValue) >= 0)
			{
				current_position -= SlideValue;
//				User_Canvas[CanNum].Mem_X = current_position;
				TWLL_WaitDisplayBlank(1);
//				TWLL_Canvas_Init(&User_Canvas[CanNum]);
//				TWLL_BlockTransfer(0, 480+272, 480, 50, current_position, 480, 16);
				TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
			}
		}
		else if(moveDir==APP_TSC_U)//direction is up
		{
//			Printf("\nmove up\n");
/*		
///			InitPageValue(RADIOPAGE_IDX);
///			ZDrawSlidePageCtrl(RADIOPAGE_IDX,moveDir);
			MoveStatus=moveDir;
			SlideValue=0;
			Y_Old=StartPtY;
			SlideValue+=(Y_Old-Y_New)/2;
			if(SlideValue>30000) SlideValue=0;
			if(SlideValue>=470) SlideValue=470;
			Y_Old=Y_New;
			User_Canvas[CanNum].Mem_Y=SlideValue+480;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
*/			
		}
		else if(moveDir==APP_TSC_D)// direction is down
		{
//			Printf("\nmove down\n");
/*		
			TWLL_BlockTransfer(User_Canvas[CanNum].Mem_X, User_Canvas[CanNum].Mem_Y, User_Canvas[CanNum].width, User_Canvas[CanNum].height, User_Canvas[CanNum].Mem_X, User_Canvas[CanNum].Mem_Y+480, User_Canvas[CanNum].Bits_Per_Pixel);
			User_Canvas[CanNum].Mem_Y=480+480;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
			User_Canvas[CanNum].Mem_Y=480;
///			InitPageValue(BLUETOOTHPAGE_IDX);
///			ZDrawSlidePageCtrl(BLUETOOTHPAGE_IDX,moveDir);
			MoveStatus=moveDir;
			SlideValue=480;
			Y_Old=StartPtY;
			SlideValue-=(Y_New-Y_Old)/2;
			if(SlideValue>60000) SlideValue=0;
			if(SlideValue>=480) SlideValue=480;
			Y_Old=Y_New;
			User_Canvas[CanNum].Mem_Y=SlideValue+480;
			//Printf("\SlideValue=%x\r\n",SlideValue);
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
*/			
		}
	}
	else if (MoveStatus == moveDir)// if move at same direction
	{
		if (moveDir == APP_TSC_L)// direction is left
		{
			Printf("\nmoving left %d\n", current_position);

			SlideValue = (X_Old - X_New);
//			if(SlideValue>30000) SlideValue=0;
//			if(SlideValue>=780) SlideValue=780;
			X_Old = X_New;
//			current_position += SlideValue;
			if ((current_position + SlideValue) <= (1271 - 480))
			{
				current_position += SlideValue;
//				User_Canvas[CanNum].Mem_X = current_position;
				TWLL_WaitDisplayBlank(1);
//				TWLL_Canvas_Init(&User_Canvas[CanNum]);
//				TWLL_BlockTransfer(0, 480+272, 480, 50, current_position, 480, 16);
				TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
			}			
		}
		else if (moveDir == APP_TSC_R)// direction is right
		{
			Printf("\nmoving right %d\n", current_position);

			SlideValue = (X_New - X_Old);
//			if(SlideValue>60000) SlideValue=0;
//			if(SlideValue>=800) SlideValue=800;
			X_Old = X_New;
//			current_position -= SlideValue;
			if ((current_position - SlideValue) >= 0)
			{
				current_position -= SlideValue;
//				User_Canvas[CanNum].Mem_X = current_position;
				TWLL_WaitDisplayBlank(1);
//				TWLL_Canvas_Init(&User_Canvas[CanNum]);
//				TWLL_BlockTransfer(0, 480+272, 480, 50, current_position, 480, 16);
				TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
			}		
		}
		else if(moveDir==APP_TSC_U)
		{
/*		
			SlideValue+=(Y_Old-Y_New);
			if(SlideValue>30000) SlideValue=0;
			if(SlideValue>=470) SlideValue=470;
			Y_Old=Y_New;
			User_Canvas[CanNum].Mem_Y=SlideValue+480;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
*/			
		}
		else if(moveDir==APP_TSC_D)// direction is down
		{
/*		
			SlideValue-=(Y_New-Y_Old);
			if(SlideValue>60000) SlideValue=0;
			if(SlideValue>=480) SlideValue=480;
			Y_Old=Y_New;
			User_Canvas[CanNum].Mem_Y=SlideValue+480;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
*/			
		}
		//lpPage=(LPUIPAGE)GetPageHandle(HOMEPAGE_IDX);
		//CanNum=lpPage->nWinno;
	}
	#endif
}

/*
 Function name: OnHomePageTouchMoved
 Page name:     HomePage
 Page id:       0
 */
void OnHomePageTouchMoved(U16 px, U16 py)
{
	#ifdef Support_PagerSlide
	U8	moveDir;
	U16 i,CanNum;
	LPUIPAGE  lpPage;

///	lpPage=(LPUIPAGE)GetPageHandle(HOMEPAGE_IDX);
	CanNum=lpPage->nWinno;

	if(MoveStatus==APP_TSC_L)// direction is left
	{
		MoveStatus = 0xff;
/*	
		i=SlideValue;

		do {
			i += 20;
			User_Canvas[CanNum].Mem_X=i;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
		} while ( i < 780 );

		User_Canvas[CanNum].Mem_X=0;
		TWLL_BlockTransfer(User_Canvas[CanNum].Mem_X+800, User_Canvas[CanNum].Mem_Y, User_Canvas[CanNum].width, User_Canvas[CanNum].height, User_Canvas[CanNum].Mem_X, User_Canvas[CanNum].Mem_Y, User_Canvas[CanNum].Bits_Per_Pixel);
///		lpPage=(LPUIPAGE)GetPageHandle(DVDPAGE_IDX);
		TWLL_WaitDisplayBlank(1);
		TWLL_Canvas_Init(&User_Canvas[lpPage->nWinno]);
		ZDestroySlidePage();
///		ZActiveSlidePage(DVDPAGE_IDX);
		MoveStatus=0xff;
		Change_PIPMode(PIP_SHOW);
		Update_Mode();
*/		
	}
	else if(MoveStatus==APP_TSC_R)// direction is right
	{
		MoveStatus = 0xff;
/*	
		i=SlideValue;
		do {
			i -= 20;
			User_Canvas[CanNum].Mem_X=i;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
		} while ( i >20 );

		User_Canvas[CanNum].Mem_X=0;
///		lpPage=(LPUIPAGE)GetPageHandle(SETTINGPAGE_IDX);
		TWLL_WaitDisplayBlank(1);
		TWLL_Canvas_Init(&User_Canvas[lpPage->nWinno]);
		TWLL_BlockTransfer(User_Canvas[lpPage->nWinno].Mem_X, User_Canvas[lpPage->nWinno].Mem_Y, User_Canvas[lpPage->nWinno].width, User_Canvas[lpPage->nWinno].height, User_Canvas[lpPage->nWinno].Mem_X+800, User_Canvas[lpPage->nWinno].Mem_Y, User_Canvas[lpPage->nWinno].Bits_Per_Pixel);
		ZDestroySlidePage();
///		ZActiveSlidePage(SETTINGPAGE_IDX);

		MoveStatus=0xff;
*/
	}
	else if(MoveStatus==APP_TSC_U)// direction is up
	{
/*	
		i=SlideValue;

		do {
			i += 10;
			User_Canvas[CanNum].Mem_Y=i+480;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
		} while ( i < 470 );

		User_Canvas[CanNum].Mem_Y=480;
		TWLL_BlockTransfer(User_Canvas[CanNum].Mem_X, User_Canvas[CanNum].Mem_Y+480, User_Canvas[CanNum].width, User_Canvas[CanNum].height, User_Canvas[CanNum].Mem_X, User_Canvas[CanNum].Mem_Y, User_Canvas[CanNum].Bits_Per_Pixel);
///		lpPage=(LPUIPAGE)GetPageHandle(RADIOPAGE_IDX);
		TWLL_WaitDisplayBlank(1);
		TWLL_Canvas_Init(&User_Canvas[lpPage->nWinno]);
		TWLL_BlockTransfer(User_Canvas[CanNum].Mem_X, User_Canvas[CanNum].Mem_Y+480, User_Canvas[CanNum].width, User_Canvas[CanNum].height, User_Canvas[CanNum].Mem_X+800, User_Canvas[CanNum].Mem_Y, User_Canvas[CanNum].Bits_Per_Pixel);
		ZDestroySlidePage();
///		ZActiveSlidePage(RADIOPAGE_IDX);
		MoveStatus=0xff;
*/
	}
	else if(MoveStatus==APP_TSC_D)// direction is down
	{
/*	
		i=SlideValue;
		do {
			i -= 10;
			User_Canvas[CanNum].Mem_Y=i+480;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
		} while ( i >10 );

		User_Canvas[CanNum].Mem_Y=480;
///		lpPage=(LPUIPAGE)GetPageHandle(BLUETOOTHPAGE_IDX);
		TWLL_WaitDisplayBlank(1);
		TWLL_Canvas_Init(&User_Canvas[lpPage->nWinno]);
		TWLL_BlockTransfer(User_Canvas[lpPage->nWinno].Mem_X, User_Canvas[lpPage->nWinno].Mem_Y, User_Canvas[lpPage->nWinno].width, User_Canvas[lpPage->nWinno].height, User_Canvas[lpPage->nWinno].Mem_X+800, User_Canvas[lpPage->nWinno].Mem_Y, User_Canvas[lpPage->nWinno].Bits_Per_Pixel);
		ZDestroySlidePage();
///		ZActiveSlidePage(BLUETOOTHPAGE_IDX);

		MoveStatus=0xff;
*/		
	}
	#endif
}

/*
 Function name: OnSetupPageTouchMoving
 Page name:     SetupPage
 Page id:       1
 */
void OnSetupPageTouchMoving(U16 px, U16 py)
{
#ifdef Support_PagerSlide
	static U8	moveDir, CanNum;
	static U16	X_New, Y_New;
	LPUIPAGE  lpPage;
	int value = 0;

	//py highest three bits indicate move direction, 000 is up, 010 is down, 100 is left, 110 is right
	moveDir=py>>13;
	X_New=px;
	Y_New=py&0x1fff;

	//Printf("\nmoveDir=%bx,X_New=%d,Y_New=%x\r\n",moveDir,X_New,Y_New);

	if (MoveStatus == 0xff)
	{
		lpPage = (LPUIPAGE)GetPageHandle(SETUPPAGE_IDX);
		CanNum = lpPage->nWinno;
		if (moveDir == APP_TSC_L)// direction is left
		{
			Printf("\nstart to move left %d\n", current_position);

			MoveStatus = moveDir;
			SlideValue = 0;
			X_Old = StartPtX;
			SlideValue += (X_Old - X_New);
			X_Old = X_New;
//			current_position += SlideValue;
			if ((current_position + SlideValue) <= (800 - 480))
			{
				current_position += SlideValue;
//				User_Canvas[CanNum].Mem_X = current_position;
				TWLL_WaitDisplayBlank(1);
//				TWLL_Canvas_Init(&User_Canvas[CanNum]);
//				TWLL_BlockTransfer(0, 480+272, 480, 50, current_position, 480, 16); //re-draw setup bar
				TWLL_BlockTransfer(current_position, 480+272+76, 480, 145, 0, 480+76, 16);
			}
		}
		else if (moveDir == APP_TSC_R)// direction is right
		{
			Printf("\nstart to move right %d\n", current_position);
			MoveStatus = moveDir;
			SlideValue = 0;
			X_Old = StartPtX;
			SlideValue = (X_New-X_Old);
			X_Old = X_New;
//			current_position -= SlideValue;
			if ((current_position - SlideValue) >= 0)
			{
				current_position -= SlideValue;
//				User_Canvas[CanNum].Mem_X = current_position;
				TWLL_WaitDisplayBlank(1);
//				TWLL_Canvas_Init(&User_Canvas[CanNum]);
//				TWLL_BlockTransfer(0, 480+272, 480, 50, current_position, 480, 16);
				TWLL_BlockTransfer(current_position, 480+272+76, 480, 145, 0, 480+76, 16);
			}
		}
		else if(moveDir==APP_TSC_U)//direction is up
		{		
		}
		else if(moveDir==APP_TSC_D)// direction is down
		{		
		}
	}
	else if (MoveStatus == moveDir)// if move at same direction
	{
		if (moveDir == APP_TSC_L)// direction is left
		{
			Printf("\nmoving left %d\n", current_position);

			SlideValue = (X_Old - X_New);
//			if(SlideValue>30000) SlideValue=0;
//			if(SlideValue>=780) SlideValue=780;
			X_Old = X_New;
//			current_position += SlideValue;
			if ((current_position + SlideValue) <= (800 - 480))
			{
				current_position += SlideValue;
//				User_Canvas[CanNum].Mem_X = current_position;
				TWLL_WaitDisplayBlank(1);
//				TWLL_Canvas_Init(&User_Canvas[CanNum]);
//				TWLL_BlockTransfer(0, 480+272, 480, 50, current_position, 480, 16);
				TWLL_BlockTransfer(current_position, 480+272+76, 480, 145, 0, 480+76, 16);
			}			
		}
		else if (moveDir == APP_TSC_R)// direction is right
		{
			Printf("\nmoving right %d\n", current_position);

			SlideValue = (X_New - X_Old);
//			if(SlideValue>60000) SlideValue=0;
//			if(SlideValue>=800) SlideValue=800;
			X_Old = X_New;
//			current_position -= SlideValue;
			if ((current_position - SlideValue) >= 0)
			{
				current_position -= SlideValue;
//				User_Canvas[CanNum].Mem_X = current_position;
				TWLL_WaitDisplayBlank(1);
//				TWLL_Canvas_Init(&User_Canvas[CanNum]);
//				TWLL_BlockTransfer(0, 480+272, 480, 50, current_position, 480, 16);
				TWLL_BlockTransfer(current_position, 480+272+76, 480, 145, 0, 480+76, 16);
			}		
		}
		else if(moveDir==APP_TSC_U)
		{
		}
		else if(moveDir==APP_TSC_D)// direction is down
		{
		}
	}
#endif
}

/*
 Function name: OnSetupPageTouchMoved
 Page name:     SetupPage
 Page id:       1
 */
void OnSetupPageTouchMoved(U16 px, U16 py)
{
#ifdef Support_PagerSlide
	U8	moveDir;
	U16 i,CanNum;
	LPUIPAGE  lpPage;

/// lpPage=(LPUIPAGE)GetPageHandle(HOMEPAGE_IDX);
	CanNum=lpPage->nWinno;

	if(MoveStatus==APP_TSC_L)// direction is left
	{
		MoveStatus = 0xff;
/*	
		i=SlideValue;

		do {
			i += 20;
			User_Canvas[CanNum].Mem_X=i;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
		} while ( i < 780 );

		User_Canvas[CanNum].Mem_X=0;
		TWLL_BlockTransfer(User_Canvas[CanNum].Mem_X+800, User_Canvas[CanNum].Mem_Y, User_Canvas[CanNum].width, User_Canvas[CanNum].height, User_Canvas[CanNum].Mem_X, User_Canvas[CanNum].Mem_Y, User_Canvas[CanNum].Bits_Per_Pixel);
/// 	lpPage=(LPUIPAGE)GetPageHandle(DVDPAGE_IDX);
		TWLL_WaitDisplayBlank(1);
		TWLL_Canvas_Init(&User_Canvas[lpPage->nWinno]);
		ZDestroySlidePage();
/// 	ZActiveSlidePage(DVDPAGE_IDX);
		MoveStatus=0xff;
		Change_PIPMode(PIP_SHOW);
		Update_Mode();
*/		
	}
	else if(MoveStatus==APP_TSC_R)// direction is right
	{
		MoveStatus = 0xff;
/*	
		i=SlideValue;
		do {
			i -= 20;
			User_Canvas[CanNum].Mem_X=i;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
		} while ( i >20 );

		User_Canvas[CanNum].Mem_X=0;
/// 	lpPage=(LPUIPAGE)GetPageHandle(SETTINGPAGE_IDX);
		TWLL_WaitDisplayBlank(1);
		TWLL_Canvas_Init(&User_Canvas[lpPage->nWinno]);
		TWLL_BlockTransfer(User_Canvas[lpPage->nWinno].Mem_X, User_Canvas[lpPage->nWinno].Mem_Y, User_Canvas[lpPage->nWinno].width, User_Canvas[lpPage->nWinno].height, User_Canvas[lpPage->nWinno].Mem_X+800, User_Canvas[lpPage->nWinno].Mem_Y, User_Canvas[lpPage->nWinno].Bits_Per_Pixel);
		ZDestroySlidePage();
/// 	ZActiveSlidePage(SETTINGPAGE_IDX);

		MoveStatus=0xff;
*/
	}
	else if(MoveStatus==APP_TSC_U)// direction is up
	{
	}
	else if(MoveStatus==APP_TSC_D)// direction is down
	{	
	}
#endif
}

void OnButton17TouchMoving(LPUIPBUTTON button, U16 px, U16 py)
{
#ifdef Support_PagerSlide
	static U8 moveDir;
	static U16 X_New,Y_New;
	int value = 0;

	//py highest three bits indicate move direction, 000 is up, 010 is down, 100 is left, 110 is right
	moveDir = py >> 13;
	X_New = px;
	Y_New = py & 0x1fff;

//	OSD_LoadBmp((const U8 *)&SystemIcon[0], 0, 480+272+272, 16);

	//Printf("\nmoveDir=%bx,X_New=%d,Y_New=%x\r\n",moveDir,X_New,Y_New);

	if (MoveStatus == 0xff)
	{
		if (moveDir == APP_TSC_U)
		{
			MoveStatus  = moveDir;
			SlideValue  = 0;
			Y_Old       = StartPtY;
			SlideValue += (Y_Old - Y_New) / 2;
			Y_Old       = Y_New;
			Printf("\nstart to move up %x\n", SlideValue);

//			TWLL_WaitDisplayBlank(1);
//			TWLL_BlockTransfer(0, 480+272+272+SlideValue, 60, 80, button->rect.left + current_position, 480+50, 16);			
//TWLL_BlockTransfer(0, 480+272+272+SlideValue, 60, 80, current_position, 480+50, 16);			
//TWLL_BlockTransfer(0, 480+272+272+SlideValue, 60, 80, 50, 480+50, 16);			
/*		
///			InitPageValue(RADIOPAGE_IDX);
///			ZDrawSlidePageCtrl(RADIOPAGE_IDX,moveDir);
			MoveStatus=moveDir;
			SlideValue=0;
			Y_Old=StartPtY;
			SlideValue+=(Y_Old-Y_New)/2;
			if(SlideValue>30000) SlideValue=0;
			if(SlideValue>=470) SlideValue=470;
			Y_Old=Y_New;
			User_Canvas[CanNum].Mem_Y=SlideValue+480;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
*/			
		}
		else if (moveDir == APP_TSC_D)
		{
			MoveStatus  = moveDir;
			SlideValue  = 480;
			Y_Old       = StartPtY;
			SlideValue -= (Y_New - Y_Old) / 2;
			Y_Old       = Y_New;
			Printf("\nstart to move down %x\n", SlideValue);
			
//			TWLL_WaitDisplayBlank(1);
//			TWLL_BlockTransfer(0, 480+272+272+SlideValue, 60, 80, button->rect.left + current_position, 480+50, 16);			
//			TWLL_BlockTransfer(0, 480+272+272+SlideValue, 60, 80, current_position, 480+50, 16);			
//TWLL_BlockTransfer(0, 480+272+272+SlideValue, 60, 80, 50, 480+50, 16);			
/*		
			TWLL_BlockTransfer(User_Canvas[CanNum].Mem_X, User_Canvas[CanNum].Mem_Y, User_Canvas[CanNum].width, User_Canvas[CanNum].height, User_Canvas[CanNum].Mem_X, User_Canvas[CanNum].Mem_Y+480, User_Canvas[CanNum].Bits_Per_Pixel);
			User_Canvas[CanNum].Mem_Y=480+480;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
			User_Canvas[CanNum].Mem_Y=480;
///			InitPageValue(BLUETOOTHPAGE_IDX);
///			ZDrawSlidePageCtrl(BLUETOOTHPAGE_IDX,moveDir);
			MoveStatus=moveDir;
			SlideValue=480;
			Y_Old=StartPtY;
			SlideValue-=(Y_New-Y_Old)/2;
			if(SlideValue>60000) SlideValue=0;
			if(SlideValue>=480) SlideValue=480;
			Y_Old=Y_New;
			User_Canvas[CanNum].Mem_Y=SlideValue+480;
			//Printf("\SlideValue=%x\r\n",SlideValue);
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
*/			
		}
	}
	else if (MoveStatus == moveDir)
	{
		if (moveDir == APP_TSC_U)
		{
			SlideValue += (Y_Old-Y_New);
			Y_Old       = Y_New;
			Printf("\nmoving up %x\n", SlideValue);

//			TWLL_WaitDisplayBlank(1);
//			TWLL_BlockTransfer(0, 480+272+272+SlideValue, 60, 80, button->rect.left + current_position, 480+50, 16);			
//			TWLL_BlockTransfer(0, 480+272+272+SlideValue, 60, 80, current_position, 480+50, 16);			
//TWLL_BlockTransfer(0, 480+272+272+SlideValue, 60, 80, 50, 480+50, 16);			
/*		
			SlideValue+=(Y_Old-Y_New);
			if(SlideValue>30000) SlideValue=0;
			if(SlideValue>=470) SlideValue=470;
			Y_Old=Y_New;
			User_Canvas[CanNum].Mem_Y=SlideValue+480;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
*/			
		}
		else if (moveDir == APP_TSC_D)
		{
			SlideValue -= (Y_New-Y_Old);
			Y_Old       = Y_New;
			Printf("\nmoving down %x\n", SlideValue);

//			TWLL_WaitDisplayBlank(1);
//			TWLL_BlockTransfer(0, 480+272+272+SlideValue, 60, 80, button->rect.left + current_position, 480+50, 16);			
//			TWLL_BlockTransfer(0, 480+272+272+SlideValue, 60, 80, current_position, 480+50, 16);			
//TWLL_BlockTransfer(0, 480+272+272+SlideValue, 60, 80, 50, 480+50, 16);			
/*		
			SlideValue-=(Y_New-Y_Old);
			if(SlideValue>60000) SlideValue=0;
			if(SlideValue>=480) SlideValue=480;
			Y_Old=Y_New;
			User_Canvas[CanNum].Mem_Y=SlideValue+480;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
*/			
		}
	}
#endif	
}

void OnButton17TouchMoved(U16 px, U16 py)
{
#ifdef Support_PagerSlide
	U8 moveDir;

	if (MoveStatus == APP_TSC_U)
	{
		MoveStatus = 0xff;	
/*	
		i=SlideValue;

		do {
			i += 10;
			User_Canvas[CanNum].Mem_Y=i+480;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
		} while ( i < 470 );

		User_Canvas[CanNum].Mem_Y=480;
		TWLL_BlockTransfer(User_Canvas[CanNum].Mem_X, User_Canvas[CanNum].Mem_Y+480, User_Canvas[CanNum].width, User_Canvas[CanNum].height, User_Canvas[CanNum].Mem_X, User_Canvas[CanNum].Mem_Y, User_Canvas[CanNum].Bits_Per_Pixel);
///		lpPage=(LPUIPAGE)GetPageHandle(RADIOPAGE_IDX);
		TWLL_WaitDisplayBlank(1);
		TWLL_Canvas_Init(&User_Canvas[lpPage->nWinno]);
		TWLL_BlockTransfer(User_Canvas[CanNum].Mem_X, User_Canvas[CanNum].Mem_Y+480, User_Canvas[CanNum].width, User_Canvas[CanNum].height, User_Canvas[CanNum].Mem_X+800, User_Canvas[CanNum].Mem_Y, User_Canvas[CanNum].Bits_Per_Pixel);
		ZDestroySlidePage();
///		ZActiveSlidePage(RADIOPAGE_IDX);
		MoveStatus=0xff;
*/
	}
	else if (MoveStatus == APP_TSC_D)
	{
		MoveStatus = 0xff;	
/*	
		i=SlideValue;
		do {
			i -= 10;
			User_Canvas[CanNum].Mem_Y=i+480;
			TWLL_WaitDisplayBlank(1);
			TWLL_Canvas_Init(&User_Canvas[CanNum]);
		} while ( i >10 );

		User_Canvas[CanNum].Mem_Y=480;
///		lpPage=(LPUIPAGE)GetPageHandle(BLUETOOTHPAGE_IDX);
		TWLL_WaitDisplayBlank(1);
		TWLL_Canvas_Init(&User_Canvas[lpPage->nWinno]);
		TWLL_BlockTransfer(User_Canvas[lpPage->nWinno].Mem_X, User_Canvas[lpPage->nWinno].Mem_Y, User_Canvas[lpPage->nWinno].width, User_Canvas[lpPage->nWinno].height, User_Canvas[lpPage->nWinno].Mem_X+800, User_Canvas[lpPage->nWinno].Mem_Y, User_Canvas[lpPage->nWinno].Bits_Per_Pixel);
		ZDestroySlidePage();
///		ZActiveSlidePage(BLUETOOTHPAGE_IDX);

		MoveStatus=0xff;
*/		
	}
#endif
}	

// Pager reply function declaration end.


// Button reply function declaration start:


/*
 Function name: OnsetupClick
 Ctrl name:     setup
 Ctrl id:       1
 */
void Onbtn1Click(void)
{
	Printf("Onbtn1Click\n");
    //Please add your button click event here
}

/*
 Function name: Onbtn2Click
 Ctrl name:     btn2
 Ctrl id:       2
 */
void Onbtn2Click(void)
{
	Printf("Onbtn2Click\n");

	osd_animation(HELP_INDEX, HELP_LENGTH);

	ZCreatePage(0);

	TWLL_WaitDisplayBlank(1);
	TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
}

/*
 Function name: Onbtn3Click
 Ctrl name:     btn3
 Ctrl id:       3
 */
void Onbtn3Click(void)
{
	U8 i;
	U8 sta;
	
	Printf("Onbtn3Click\n");
/*
	for (i = 0; i<11; i++)
	{
        ZGetCtrlParam(i+3, ZVAL_VALUE, &sta);
		if (sta == 1)
		{
			ZSetCtrlFocus(3+i, 0);
		}
	}
*/
	ZSetCtrlFocus(3, 1);

	TWLL_WaitDisplayBlank(1);
	TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);

	current_position = 0;
	ZCreatePage(1); 
}

/*
 Function name: Onbtn4Click
 Ctrl name:     btn4
 Ctrl id:       4
 */
void Onbtn4Click(void)
{
	Printf("Onbtn4Click\n");
	ZSetCtrlFocus(4, 1);
	TWLL_WaitDisplayBlank(1);
	TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
}

/*
 Function name: Onbtn5Click
 Ctrl name:     btn5
 Ctrl id:       5
 */
void Onbtn5Click(void)
{
	Printf("Onbtn5Click\n");
	ZSetCtrlFocus(5, 1);
	TWLL_WaitDisplayBlank(1);
	TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
}

/*
 Function name: Onbtn6Click
 Ctrl name:     btn6
 Ctrl id:       6
 */
void Onbtn6Click(void)
{
	Printf("Onbtn6Click\n");
	ZSetCtrlFocus(6, 1);
	TWLL_WaitDisplayBlank(1);
	TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
}

/*
 Function name: Onbtn7Click
 Ctrl name:     btn7
 Ctrl id:       7
 */
void Onbtn7Click(void)
{
	Printf("Onbtn7Click\n");
	ZSetCtrlFocus(7, 1);
	TWLL_WaitDisplayBlank(1);
	TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
}

/*
 Function name: Onbtn8Click
 Ctrl name:     btn8
 Ctrl id:       8
 */
void Onbtn8Click(void)
{
	Printf("Onbtn8Click\n");
	ZSetCtrlFocus(8, 1);
	TWLL_WaitDisplayBlank(1);
	TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
}

/*
 Function name: Onbtn9Click
 Ctrl name:     btn9
 Ctrl id:       9
 */
void Onbtn9Click(void)
{
	Printf("Onbtn9Click\n");
	ZSetCtrlFocus(9, 1);
	TWLL_WaitDisplayBlank(1);
	TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
}

/*
 Function name: Onbtn10Click
 Ctrl name:     btn10
 Ctrl id:       10
 */
void Onbtn10Click(void)
{
	Printf("Onbtn10Click\n");
	ZSetCtrlFocus(10, 1);
	TWLL_WaitDisplayBlank(1);
	TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
}

/*
 Function name: Onbtn11Click
 Ctrl name:     btn11
 Ctrl id:       11
 */
void Onbtn11Click(void)
{
	Printf("Onbtn11Click\n");
	ZSetCtrlFocus(11, 1);
	TWLL_WaitDisplayBlank(1);
	TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
}

/*
 Function name: Onbtn12Click
 Ctrl name:     btn12
 Ctrl id:       12
 */
void Onbtn12Click(void)
{
	Printf("Onbtn12Click\n");
	ZSetCtrlFocus(12, 1);
	TWLL_WaitDisplayBlank(1);
	TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
}

/*
 Function name: Onbtn13Click
 Ctrl name:     btn13
 Ctrl id:       13
 */
void Onbtn13Click(void)
{
	Printf("Onbtn13Click\n");
	ZSetCtrlFocus(13, 1);
	TWLL_WaitDisplayBlank(1);
	TWLL_BlockTransfer(current_position, 480+272+50, 480, 169, 0, 480+50, 16);
}

/*
 Function name: Onbtn15Click
 Ctrl name:     btn15
 Ctrl id:       15
 */
void Onbtn15Click(void)
{
	Printf("clicked return button\n");
	current_position = 0;
	ZCreatePage(0); 
}

/*
 Function name: Onbtn16Click
 Ctrl name:     btn16
 Ctrl id:       16
 */
void Onbtn16Click(void)
{
	Printf("Onbtn16Click\n");

	osd_animation(HELP_INDEX, HELP_LENGTH);

	ZCreatePage(1);

	TWLL_WaitDisplayBlank(1);
	TWLL_BlockTransfer(current_position, 480+272+76, 480, 145, 0, 480+76, 16);
}

/*
 Function name: Onbtn17Click
 Ctrl name:     btn17
 Ctrl id:       17
 */
void Onbtn17Click(void)
{
	Printf("Onbtn17Click\n");
    //Please add your button click event here
}

/*
 Function name: Onbtn18Click
 Ctrl name:     btn18
 Ctrl id:       18
 */
void Onbtn18Click(void)
{
    //Please add your button click event here
}

/*
 Function name: Onbtn19Click
 Ctrl name:     btn19
 Ctrl id:       19
 */
void Onbtn19Click(void)
{
    //Please add your button click event here
}

/*
 Function name: Onbtn20Click
 Ctrl name:     btn20
 Ctrl id:       20
 */
void Onbtn20Click(void)
{
    //Please add your button click event here
}

/*
 Function name: Onbtn21Click
 Ctrl name:     btn21
 Ctrl id:       21
 */
void Onbtn21Click(void)
{
    //Please add your button click event here
}

// Button reply function declaration end.


void InitCtrlValue(HUICTRL hCtrl)
{
	U8 Value;
	U16 Value1;
	LPUIPBUTTON  lpBtn;

	switch(hCtrl)
	{
		/************OSDSetupPager******************/
///		case OSDSETLANGVALBTN_IDX:
			lpBtn=(LPUIPBUTTON )GetCtrlHandle(hCtrl);
			Value=GetLanguageStatus();
			if(Value==1)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"Chinese");
			else
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"English");
			break;
///		case OSDSETTIMEVALBTN_IDX:
			lpBtn=(LPUIPBUTTON )GetCtrlHandle(hCtrl);
			Value=GetTimeOutStatus();
			if(Value==0)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"5S");
			else if(Value==1)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"15S");
			else if(Value==2)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"30S");
			else if(Value==3)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"45S");
			else if(Value==4)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"60S");
			break;
///		case OSDSETTRANSVALBTN_IDX:
			lpBtn=(LPUIPBUTTON )GetCtrlHandle(hCtrl);
			Value=GetTransparentValue();
			ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"%bd",Value);
			break;
///		case OSDSETTRANSPPRO_IDX:
			Value=GetTransparentValue();
///			ZSetCtrlValue(OSDSETTRANSPPRO_IDX,Value,0);
			break;
		/********************VideoSetupPager************************/
///		case VIDEOSETBRIVALBTN_IDX:
			lpBtn=(LPUIPBUTTON )GetCtrlHandle(hCtrl);
			Value=GetBrightnessValue();
			ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"%bd",Value);
			break;
///		case VIDEOSETBRIGHTPRO_IDX:
			Value=GetBrightnessValue();
///			ZSetCtrlValue(VIDEOSETBRIGHTPRO_IDX,Value,0);
			break;
///		case VIDEOSETCONTRVALBTN_IDX:
			lpBtn=(LPUIPBUTTON )GetCtrlHandle(hCtrl);
			Value=GetContrastValue();
			ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"%bd",Value);
			break;
///		case VIDEOSETCONTRASTPRO_IDX:
			Value=GetContrastValue();
///			ZSetCtrlValue(VIDEOSETCONTRASTPRO_IDX,Value,0);
			break;
///		case VIDEOSETSATVALBTN_IDX:
			lpBtn=(LPUIPBUTTON )GetCtrlHandle(hCtrl);
			Value=GetSaturationValue();
			ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"%bd",Value);
			break;
///		case VIDEOSETSATURATIONPRO_IDX:
			Value=GetSaturationValue();
///			ZSetCtrlValue(VIDEOSETSATURATIONPRO_IDX,Value,0);
			break;
		/********************RadioPager************************/
///		case RADIOSHOWFRESTRBTN_IDX:
			lpBtn=(LPUIPBUTTON )GetCtrlHandle(hCtrl);
			Value1=GetFreStringStatus();
			ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"%d.3 MHz",Value1);
			break;
///		case RADIOSHOWFREQPRO_IDX:
			Value=GetFreProValue();
///			ZSetCtrlValue(RADIOSHOWFREQPRO_IDX,Value,0);
			break;
		/********************PIPSettingPager************************/
///		case PIPSETSOURCEVALBTN_IDX:
			lpBtn=(LPUIPBUTTON )GetCtrlHandle(hCtrl);
			Value=GetPIPSourceStatus();
			if(Value==0)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"CVBS");
			else if(Value==1)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"YC");
			else if(Value==2)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"ExCVBS");
			else if(Value==3)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"ExYC");
			else if(Value==4)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"PC");
			else if(Value==5)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"YPbPr");
			break;
///		case PIPSETSIZEVALBTN_IDX:
			lpBtn=(LPUIPBUTTON )GetCtrlHandle(hCtrl);
			Value=GetPIPSizeStatus();
			if(Value==0)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"Small");
			else if(Value==1)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"Middle");
			else if(Value==2)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"Large");
			break;
///		case PIPSETPOSVALBTN_IDX:
			lpBtn=(LPUIPBUTTON )GetCtrlHandle(hCtrl);
			Value=GetPIPPositionStatus();
			if(Value==0)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"LUp");
			else if(Value==1)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"RUp");
			else if(Value==2)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"LDown");
			else if(Value==3)
				ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"RDown");
			break;
///		case PIPSETTRANSVALBTN_IDX:
			lpBtn=(LPUIPBUTTON )GetCtrlHandle(hCtrl);
			Value=GetPIPTransparentValue();
			ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"%bd",Value);
			break;
///		case PIPSETTRANSPRO_IDX:
			Value=GetPIPTransparentValue();
///			ZSetCtrlValue(PIPSETTRANSPRO_IDX,Value,0);
			break;
		default:
			break;
	}
}

void InitPageValue(HUICTRL page_id)
{
	U8 val;
	val = GetLanguageStatus();
	if(val==1)
	{
		OSDLang=1;
	}
	else if(val==0)
	{
		OSDLang=0;
	}

	TWLL_WaitDisplayBlank(1);
	TWLL_SetWin_GlobalAlpha(3, GetTransparentValue());

    	switch(page_id)
   	{
    	default:
    	break;
    	}
}

void _OSDCommon_Update_ProgressBar_Status( U16 Ctrl, U8 Value )
{
	ZSetCtrlValue(Ctrl,Value,0);
	
	#ifndef Update_AvoidBlink
	TWLL_WaitOSDBlank(1);
	ZUIRedrawCtrl(Ctrl);
	#endif

	#ifdef Update_AvoidBlink
//	TWLL_UpdateProgressBar_WithBT(Ctrl);
	#endif
}

void _OSDCommon_Update_ProgressBar_Value( U16 Ctrl, U8 Value )
{
	LPUIPBUTTON  lpBtn;

	lpBtn=(LPUIPBUTTON )GetCtrlHandle(Ctrl);
	
	ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"%bd",Value);
	
	#ifndef Update_AvoidBlink
	TWLL_WaitOSDBlank(1);
	ZUIRedrawCtrl(Ctrl);
	#endif
	
	#ifdef Update_AvoidBlink
//	TWLL_UpdateButton_WithBT(Ctrl);
	#endif

}

/**************OSDSetupPager*****************/
void _OSDSetupPager_Update_Language_Status( U16 Ctrl, U8 Value )
{
	LPUIPBUTTON  lpBtn;

	lpBtn=(LPUIPBUTTON )GetCtrlHandle(Ctrl);
	
	if(Value==1)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"Chinese");
	else
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"English");
	
	#ifndef Update_AvoidBlink
	TWLL_WaitOSDBlank(1);
	ZUIRedrawCtrl(Ctrl);

	//lpBtn=(LPUIPBUTTON )GetCtrlHandle(OSDSETLANGTITLEBTN_IDX);
	ZUIRedrawCtrl(OSDSETLANGTITLEBTN_IDX);

	//lpBtn=(LPUIPBUTTON )GetCtrlHandle(OSDSETTIMETITLEBTN_IDX);
	ZUIRedrawCtrl(OSDSETTIMETITLEBTN_IDX);

	//lpBtn=(LPUIPBUTTON )GetCtrlHandle(OSDSETTRANTITLEBTN_IDX);
	ZUIRedrawCtrl(OSDSETTRANTITLEBTN_IDX);
	#endif
	
	#ifdef Update_AvoidBlink
//	TWLL_UpdateButton_WithBT(Ctrl);
///	TWLL_UpdateButton_WithBT(OSDSETLANGTITLEBTN_IDX);
///	TWLL_UpdateButton_WithBT(OSDSETTIMETITLEBTN_IDX);
///	TWLL_UpdateButton_WithBT(OSDSETTRANTITLEBTN_IDX);
	#endif

	
}

U8 GetLanguageStatus(void)
{
	U8 value;
	value=LanguageStatus;
	return value;
}

void SetLanguageStatus(U8 value)
{
	LanguageStatus=value;
}

void _OSDSetupPager_Update_TimeOut_Status( U16 Ctrl, U8 Value )
{
	LPUIPBUTTON  lpBtn;

	lpBtn=(LPUIPBUTTON )GetCtrlHandle(Ctrl);
	
	if(Value==0)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"5S");
	else if(Value==1)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"15S");
	else if(Value==2)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"30S");
	else if(Value==3)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"45S");
	else if(Value==4)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"60S");
	
	#ifndef Update_AvoidBlink
	TWLL_WaitOSDBlank(1);
	ZUIRedrawCtrl(Ctrl);
	#endif
	
	#ifdef Update_AvoidBlink
//	TWLL_UpdateButton_WithBT(Ctrl);
	#endif

}

U8 GetTimeOutStatus(void)
{
	U8 value;
	value=TimeOutStatus;
	return value;
}

void SetTimeOutStatus(U8 value)
{
	TimeOutStatus=value;
}

U8 GetTransparentValue(void)
{
	U8 value;
	value=TransparentValue;
	return value;
}

void SetTransparentValue(U8 value)
{
	TransparentValue=value;
	TWLL_WaitOSDBlank(1);
	TWLL_SetWin_GlobalAlpha(3, TransparentValue);
}

/**************VideoSetupPager*****************/
U8 GetBrightnessValue(void)
{
	U8 value;
	value=BrightnessValue;
	return value;
}

void SetBrightnessValue(U8 value)
{
	BrightnessValue=value;
	value = (U8)((((U32)(BrightnessValue))<<8)/100);
	Set_Brightness(value);
}

U8 GetContrastValue(void)
{
	U8 value;
	value=ContrastValue;
	return value;
}

void SetContrastValue(U8 value)
{
	ContrastValue=value;
	value = (U8)((((U32)(ContrastValue))<<8)/100);
	Set_Contrast(value);
}

U8 GetSaturationValue(void)
{
	U8 value;
	value=SaturationValue;
	return value;
}

void SetSaturationValue(U8 value)
{
	SaturationValue=value;
	value = (U8)((((U32)(SaturationValue))<<8)/100);
	Set_Hue(value);
}

/********************RadioPager************************/
void _OSDRadioPager_Update_FreString_Status( U16 Ctrl, U16 Value )
{
	LPUIPBUTTON  lpBtn;

	lpBtn=(LPUIPBUTTON )GetCtrlHandle(Ctrl);
	
	ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"%d.3 MHz",Value);
	
	#ifndef Update_AvoidBlink
	TWLL_WaitOSDBlank(1);
	ZUIRedrawCtrl(Ctrl);
	#endif
	
	#ifdef Update_AvoidBlink
//	TWLL_UpdateButton_WithBT(Ctrl);
	#endif

}

U16 GetFreStringStatus(void)
{
	U16 value;
	value=RadioShowStringStatus;
	return value;
}

void SetFreStringStatus(U16 value)
{
	RadioShowStringStatus=value;
}

U8 GetFreProValue(void)
{
	U8 value;
	value=RadioShowProValue;
	return value;
}

void SetFreProValue(U8 value)
{
	RadioShowProValue=value;
}

/********************BlueToothPager************************/
void _OSDBlueToothPager_Update_DialString_Status( U16 Ctrl, U8 Value )
{
	U8 Num,i;
	LPUIPBUTTON  lpBtn;

	lpBtn=(LPUIPBUTTON )GetCtrlHandle(Ctrl);
	Num=GetDialStringStatus();

	//Printf("\nNum=%bd\r\n",Num);
	
	/*if(Value==0)
		ZPrintf(DialP,"%bd",0);
	else if(Value==1)
		ZPrintf(DialP,"1");
	else if(Value==2)
		ZPrintf(DialP,"2");
	else if(Value==3)
		ZPrintf(DialP,"3");
	else if(Value==4)
		ZPrintf(DialP,"4");
	else if(Value==5)
		ZPrintf(DialP,"5");
	else if(Value==6)
		ZPrintf(DialP,"6");
	else if(Value==7)
		ZPrintf(DialP,"7");
	else if(Value==8)
		ZPrintf(DialP,"8");
	else if(Value==9)
		ZPrintf(DialP,"9");
	else if(Value==10)
		ZPrintf(DialP," ");
	else if(Value==11)
		ZPrintf(DialP,"*");

	Printf("\nDialP[1]=%x\r\n",DialP[1]);
	DialNum[Num]=DialP[1];
	//DialNum[Num]=0x23;

	for(i=0;i<=Num;i++)
	Printf("\nDialNum[Num]=%x\r\n",DialNum[Num]);*/

	if(Value==0)
		DialNum[Num]=0x30;
	else if(Value==1)
		DialNum[Num]=0x31;
	else if(Value==2)
		DialNum[Num]=0x32;
	else if(Value==3)
		DialNum[Num]=0x33;
	else if(Value==4)
		DialNum[Num]=0x34;
	else if(Value==5)
		DialNum[Num]=0x35;
	else if(Value==6)
		DialNum[Num]=0x36;
	else if(Value==7)
		DialNum[Num]=0x37;
	else if(Value==8)
		DialNum[Num]=0x38;
	else if(Value==9)
		DialNum[Num]=0x39;
	else if(Value==10)
		DialNum[Num]=0x20;
	else if(Value==11)
		DialNum[Num]=0x2a;

	for(i=0;i<=Num;i++)
	StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang[i]=DialNum[i];

	StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang[i]=0;
	
	/*#ifdef Update_AvoidBlink
	UpdateStatus=1;
	#endif
	ZUIRedrawCtrl(Ctrl);
	
	#ifdef Update_AvoidBlink
	//Printf("\nDispControl->XY1.X=%d\r\n",IconShowOnCanvas[lpBtn->hImageID[1]].DispControl->XY1.X);
	//Printf("\nDispControl->XY1.Y=%d\r\n",IconShowOnCanvas[lpBtn->hImageID[1]].DispControl->XY1.Y);
	//Printf("\nwidth=%d\r\n",SystemIcon[IconShowOnCanvas[lpBtn->hImageID[1]].BMP_ID].width);
	//Printf("\nheight=%d\r\n",SystemIcon[IconShowOnCanvas[lpBtn->hImageID[1]].BMP_ID].height);
	TWLL_WaitOSDBlank(1);
	TWLL_BlockTransfer((User_Canvas[IconShowOnCanvas[lpBtn->hImageID[1]].Canvas_ID].Mem_X+IconShowOnCanvas[lpBtn->hImageID[1]].DispControl->XY1.X+800),(User_Canvas[IconShowOnCanvas[lpBtn->hImageID[1]].Canvas_ID].Mem_Y+IconShowOnCanvas[lpBtn->hImageID[1]].DispControl->XY1.Y),SystemIcon[IconShowOnCanvas[lpBtn->hImageID[1]].BMP_ID].width,SystemIcon[IconShowOnCanvas[lpBtn->hImageID[1]].BMP_ID].height,(User_Canvas[IconShowOnCanvas[lpBtn->hImageID[1]].Canvas_ID].Mem_X+IconShowOnCanvas[lpBtn->hImageID[1]].DispControl->XY1.X),(User_Canvas[IconShowOnCanvas[lpBtn->hImageID[1]].Canvas_ID].Mem_Y+IconShowOnCanvas[lpBtn->hImageID[1]].DispControl->XY1.Y),16);//User_Canvas[IconShowOnCanvas[lpBtn->hImageID[1]].BMP_ID].Bits_Per_Pixel);
	//Printf("\nupdate1\r\n");
	UpdateStatus=0;
	#endif*/
	#ifndef Update_AvoidBlink
	TWLL_WaitOSDBlank(1);
	ZUIRedrawCtrl(Ctrl);
	#endif
	
	#ifdef Update_AvoidBlink
//	TWLL_UpdateButton_WithBT(Ctrl);
	#endif
}

U8 GetDialStringStatus(void)
{
	U8 value;
	value=DialStringStatus;
	return value;
}

void SetDialStringStatus(U8 value)
{
	DialStringStatus=value;
}

/**************PIPSettingPager*****************/
void _OSDPIPSettingPager_Update_PIPSource_Status( U16 Ctrl, APP_SRC Value )
{
	LPUIPBUTTON  lpBtn;

	lpBtn=(LPUIPBUTTON )GetCtrlHandle(Ctrl);
	
	if(Value==CVBS)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"CVBS");
	else if(Value==SVIDEO)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"YC");
	else if(Value==YPBPR)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"YPbPr");
	else if(Value==PC)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"PC");
	else if(Value==EXCVBS)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"ExCVBS");
	else if(Value==EXSVIDEO)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"ExYC");
	
	#ifndef Update_AvoidBlink
	TWLL_WaitOSDBlank(1);
	ZUIRedrawCtrl(Ctrl);
	#endif
	
	#ifdef Update_AvoidBlink
//	TWLL_UpdateButton_WithBT(Ctrl);
	#endif

}

U8 GetPIPSourceStatus(void)
{
	return (U8)PIPSourceStatus;
}

void SetPIPSourceStatus(APP_SRC value)
{
	PIPSourceStatus=value;
}

void _OSDPIPSettingPager_Update_PIPSize_Status( U16 Ctrl, APP_PIP_SIZE Value )
{
	LPUIPBUTTON  lpBtn;

	lpBtn=(LPUIPBUTTON )GetCtrlHandle(Ctrl);
	
	if(Value==SMALL)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"Small");
	else if(Value==MIDDLE)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"Middle");
	else if(Value==LARGE)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"Large");
	
	#ifndef Update_AvoidBlink
	TWLL_WaitOSDBlank(1);
	ZUIRedrawCtrl(Ctrl);
	#endif
	
	#ifdef Update_AvoidBlink
//	TWLL_UpdateButton_WithBT(Ctrl);
	#endif

}

U8 GetPIPSizeStatus(void)
{
	return (U8)PIPSizeStatus;
}

void SetPIPSizeStatus(APP_PIP_SIZE value)
{
	PIPSizeStatus=value;
}

void _OSDPIPSettingPager_Update_PIPPosition_Status( U16 Ctrl, APP_PIP_POS Value )
{
	LPUIPBUTTON  lpBtn;

	lpBtn=(LPUIPBUTTON )GetCtrlHandle(Ctrl);

	if(Value==LEFT_TOP)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"LUp");
	else if(Value==LEFT_BOTTOM)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"LDown");
	else if(Value==RIGHT_TOP)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"RUp");
	else if(Value==RIGHT_BOTTOM)
		ZPrintf(StringShowOnCanvas[lpBtn->textID[ZCTRL_UNFOCUS]].Character[OSDLang].Str_Lang,"RDown");
	
	#ifndef Update_AvoidBlink
	TWLL_WaitOSDBlank(1);
	ZUIRedrawCtrl(Ctrl);
	#endif
	
	#ifdef Update_AvoidBlink
//	TWLL_UpdateButton_WithBT(Ctrl);
	#endif

}

U8 GetPIPPositionStatus(void)
{
	return (U8)PIPPositionStatus;
}

void SetPIPPositionStatus(APP_PIP_POS value)
{
	PIPPositionStatus=value;
}

U8 GetPIPTransparentValue(void)
{
	U8 value;
	value=PIPTransValue;
	return value;
}

void SetPIPTransparentValue(U8 value)
{
	PIPTransValue=value;
	value = (U8)((((U32)(PIPTransValue))<<4)/100);
	Change_PIPTrans(value);
}
/*
U16 ZCreateSlidePage(U8 page_id)
{
    LPUIPAGE lppage;
    WORD CanNum;
    U8 PagerID;

    PagerID = page_id;
    lppage  = app_ui_pages[PagerID];
    CanNum  = lppage->nWinno;

    if (lppage->subPage == 0)
    {
#ifdef Used_BlockTransfer
        UIDesTroyAllActivePage(User_Canvas[CanNum].Bits_Per_Pixel);
#else
        UIDesTroyAllActivePage();
#endif
    }
    else if (255 == isValidLofiCanvasID(CanNum))
    {
        return 65535;
    }
	
    InitPageValue(PagerID);

    BlockTransStatus = 1;

    ZApp_Clear_Canvas_Page(lppage->nWinno, lppage->bcolor);
    UICreateOnePage(PagerID, lppage);

#ifdef Used_BlockTransfer
    BlockTransStatus=0;
    TWLL_Canvas_Init(&User_Canvas[CanNum]);
    TWLL_WaitDisplayBlank(1);
    if (User_Canvas[CanNum].Bits_Per_Pixel==16)
        TWLL_BlockTransfer (User_Canvas[CanNum].Mem_X+800,
            User_Canvas[CanNum].Mem_Y, User_Canvas[CanNum].width,
            User_Canvas[CanNum].height, User_Canvas[CanNum].Mem_X,
            User_Canvas[CanNum].Mem_Y, User_Canvas[CanNum].Bits_Per_Pixel);
#endif
    TWLL_Canvas_OnOff(CanNum,1);

    return 0;
}
*/
#endif
